﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;

namespace IHISCETeim.Web.MachineSys.FXModel
{
    public partial class FXFinanceLeaseUpdate : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.修改 };
            }
        }
        protected override string DWZRef
        {
            get { return "FXFinanceLeaseMasterList"; }
        }



        protected int FnncLsId
        {
            get
            {
                return GetRequestValue<int>("FnncLsId", 0);
            }
        }
        protected short NextLeaseStatus
        {
            get
            {
                return GetRequestValue<short>("NextLeaseStatus", 0);
            }
        }


        private FXFinanceLeaseInfo _objFx = null;

        protected FXFinanceLeaseInfo objFx
        {
            get
            {
                if (_objFx == null)
                    _objFx = FXFinanceLeaseController.GetById(FnncLsId);
                return _objFx;
            }
        }

        protected string GetDateShowType(object datevalue)
        {
            if (datevalue == DBNull.Value || Convert.ToDateTime(datevalue)==DateTime.MinValue)
                return "";
            DateTime dtemp = Convert.ToDateTime(datevalue);
            return dtemp.ToString("yyyy-MM-dd");
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethod", "") == "edit")
            {
                addmenu();
                
            }
        }
        private void addmenu()
        {
            //FXFinanceLeaseInfo objFxx = objFx;
            FXFinanceLeaseInfo objFxx = Request.SerializableObject<FXFinanceLeaseInfo>();
            if (objFxx.LPayYiFu > objFxx.LPay)
                AlertJson("已付首付款项金额大于应付首付款项,请重新输入");

            if (objFxx.LMFeeYiFu > objFxx.LMFee)
                AlertJson("已付管理费款项金额大于应付管理费款项,请重新输入");

            //objFxx.ORemark = objFxx.ORemark.Trim();
            bool goToNextStatus = GetRequestValue<bool>("goToNextStatus", false);
            if (goToNextStatus)
            {

                switch (objFxx.LeaseStatus)
                {
                    case 0:
                        objFxx.LeaseStatus = 1;
                        break;
                    case 1:
                        objFxx.LeaseStatus = 2;
                        break;
                    case 2:
                        objFxx.LeaseStatus = 3;
                        break;
                    case 3:
                        objFxx.LeaseStatus = 4;
                        break;
                }
            }


            bool r = FXFinanceLeaseController.Update(objFxx);

            AddLog(Permission.修改, objFxx);

            if (r)
            {
                if (IsRefreshPar)
                {
                    SuccessJson("编辑完成");
                }
                else
                {
                    SuccessAlertJson("编辑完成");
                }
            }
            else
            {

                ErrorJson("编辑失败");
            }
        }
    }
}